import {inject, observer} from "mobx-react";
import {WeaTableNew} from 'comsMobx';
import * as Public from '../public/sendMsg'

import * as conLockApi from '../apis/contractLockSend';
const WeaTable = WeaTableNew.WeaTable;
import {WeaTools, WeaTableEditable} from 'ecCom';
import {Button, Spin} from 'antd';
import {toJS} from "mobx";

@inject("myStore", "myParame")
@observer
class MainDataList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: true,
        }
    }

    componentWillReceiveProps(nextProps) {
        let {myParame} = this.props;
        const {selectedKey, toptab} = myParame;
        // this.setState({loading:true})
        if(selectedKey && toptab.length>0 && conLockApi) {
            toptab[selectedKey] && toptab[selectedKey].dataurl && conLockApi.currencyRequestPOST(toptab[selectedKey].dataurl, myParame.parame).then(result => {
                const {myStore} = this.props;
                const {tableStore} = myStore;
                tableStore.getDatas(result.sessionkey, 1);
                this.setState({loading: false})
            })
        }
    }

    setCol = () => {
        const {radioTableStore} = this.props;
        const {tableStore} = radioTableStore;
        tableStore.setColSetVisible(true);
        tableStore.tableColSet(true);
    }

    onOperatesClick = (record, index, operate, flag) => {
        if(operate && operate.linkkey) {
            if( "delete" === operate.linkkey) {//删除
                this.props.fnGoDelete(record.id);
            } else if("edit" === operate.linkkey) {
                this.props.fnEditForm(record.id);
            } else if("editpath" === operate.linkkey) {
                Public.goToPathSetting(record.workflowid, "_blank" );
            }else if("run" === operate.linkkey){
                let {immediatelyRun} = this.props.myParame;
                immediatelyRun(record.randomFieldId);
            }
        }
    }


    render() {
        const {myStore} = this.props;
        const {loading} = this.state;
        const {tableStore} = myStore;
        const style = {
            display: this.props.display ? 'none' : ""
        }

        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
                this.props.myParame.setToDoParams(toJS(selectedRowKeys));
            }
        };

        return (
            <div style={style}>
                <Spin spinning={loading}>
                    <WeaTable pageSizeOptions={[5, 10, 20]}
                              hasOrder={true}
                              needScroll={true}
                              onOperatesClick={this.onOperatesClick.bind(this)}
                              comsWeaTableStore={tableStore}
                              rowSelection={rowSelection}
                    />

                </Spin>
            </div>
        );
    }
}

export {MainDataList};